package press.xiang.controller;

import com.baomidou.mybatisplus.extension.api.R;
import lombok.AllArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import press.xiang.entity.User;
import press.xiang.service.impl.UserServiceImpl;

import java.util.List;
import java.util.UUID;

/**
 * @author xiang
 * @version 1.0
 * @description: TODO
 * @date 2022/4/21 6:43 下午
 */
@RestController
@RequestMapping("user")
@AllArgsConstructor
public class UserController {

    private final UserServiceImpl userService;

    @GetMapping("query")
    public R<List<User>> query(){
        return R.ok(new User().selectAll());
    }

    @PostMapping("save")
    public R save(@RequestBody User user){
        if (StringUtils.isEmpty(user.getId())){
            user.setId(UUID.randomUUID().toString());
        }
        return R.ok(user.insert());
    }

    @PostMapping("update")
    public R update(@RequestBody User user){
        user.updateById();
        return R.ok("success");
    }

    @PostMapping("delete")
    public R delete(@RequestBody User user){
        user.deleteById();
        return R.ok("success");
    }


}
